package com.example.lx6_8.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil.ItemCallback
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.example.base.aa.entity.AttendEntityItem
import com.example.lx6_8.R
import com.example.lx6_8.databinding.ItemAttendBinding

class AttendAdapter : PagingDataAdapter<AttendEntityItem, AttendAdapter.AttendViewHolder>(diff) {

    companion object{
        val diff = object : ItemCallback<AttendEntityItem>() {
            override fun areItemsTheSame(
                oldItem: AttendEntityItem,
                newItem: AttendEntityItem
            ): Boolean {
                return oldItem == newItem
            }

            override fun areContentsTheSame(
                oldItem: AttendEntityItem,
                newItem: AttendEntityItem
            ): Boolean {
                return oldItem == newItem
            }

        }
    }

    class AttendViewHolder(view:View) : ViewHolder(view){
        val binding = DataBindingUtil.bind<ItemAttendBinding>(view)
    }

    override fun onBindViewHolder(holder: AttendViewHolder, position: Int) {
        holder.binding?.att = getItem(position)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AttendViewHolder {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.item_attend, parent, false)
        return AttendViewHolder(view)
    }

}